package com.aaa.system.controller.api;

import com.aaa.entity.LoginInfo;
import com.aaa.entity.Notice;
import com.aaa.system.aop.annotation.Log;
import com.aaa.system.service.ILoginInfoService;
import com.aaa.system.service.INoticeService;
import com.aaa.system.vo.LoginInfoVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 响应到前端的controller类
 */
@RestController
@RequestMapping("system/api/logininfo")
public class ApiLoginInfoController {

    @Autowired
    private ILoginInfoService loginInfoService;

    /**
     * 分页动态查询所有登陆日志
     * @param current  当前页码
     * @param size  每页显示条数
     * @param loginInfoVo 登陆日志查询条件对象
     * @return
     */
    @PostMapping("selectAll/{current}/{size}")
    public Result<IPage<LoginInfo>> selectAll(
            @PathVariable Integer current,
            @PathVariable Integer size,
            @RequestBody LoginInfoVo loginInfoVo
    ){
        Result<IPage<LoginInfo>> selectAll = loginInfoService.selectAll(current,size,loginInfoVo);
        return selectAll;
    }

    /**
     * 根据登录日志id删除单个或多个登陆日志信息
     * @param infoIds 登陆日志id数组
     * @return 结果信息
     */
    @Log(title = "删除登陆日志",business_type = "3")
    @DeleteMapping("/deleteLoginInfoByIds/{infoIds}")
    public Result<Boolean> deleteLoginInfoByIds(@PathVariable Long[] infoIds){
        return loginInfoService.deleteLoginInfoByIds(infoIds);
    }

    /**
     * 清空登录日志表
     * @return
     */
    @Log(title = "清空登陆日志",business_type = "8")
    @DeleteMapping("truncateTable")
    public Result<Boolean> truncateTable(){
        return loginInfoService.truncateTable();
    }
}
